package com.example.health_life.controller;

import com.example.health_life.Response;
import com.example.health_life.dao.Userview;
import com.example.health_life.service.UserviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserviewController {

    @Autowired
    private UserviewService userviewService;

    @GetMapping("/userviews")
    public Response<List<Userview>> getUserviewList() {
        return Response.newSuccess(userviewService.getUserviewList());
    }

    @GetMapping("/userviews/{id}")
    public Response<Userview> getUserviewById(@PathVariable Integer id) {
        return Response.newSuccess(userviewService.getUserviewById(id));
    }

    @GetMapping("/userviews/user/{userId}")
    public Response<List<Userview>> getUserviewByUserId(@PathVariable Integer userId) {
        return Response.newSuccess(userviewService.getUserviewByUserId(userId));
    }

    @GetMapping("/userviews/{type}/{typeId}")
    public Response<Integer> getUserviewByTypeId(@PathVariable Byte type, @PathVariable Integer typeId) {
        return Response.newSuccess(userviewService.getUserviewByTypeId(type, typeId));
    }

    @PostMapping("/userviews")
    public Response<Integer> addUserview(@RequestBody Userview userview) {
        return Response.newSuccess(userviewService.addUserview(userview));
    }
    
}
